import type { RespDataType } from "@/components/app/loginModal/api"
import { localStore } from '@yaf/utils'
import { globalStore } from "../store/globalStore";

export type LoginUserInfo = RespDataType.UserInfo;

export default class LoginUser {
  private storeKey = "login_user"

  set = (info: any) => {
    localStore.set(this.storeKey, info);
    globalStore.setUserLogined(true);
    globalStore.setLoginUserInfo(info);
  }

  get = (): LoginUserInfo => {
    const info = localStore.get(this.storeKey)

    return info || defaultLoginUserInfo;
  }

  clear = () => {
    localStore.remove(this.storeKey);
    globalStore.setUserLogined(false);
  }
}


/**
 * 默认值
 */
const defaultLoginUserInfo: LoginUserInfo = {
  user: {
    userId: 0,
    userName: "",   // 用户名
    nickName: "",   // 昵称
    userType: "",
    amount: 0,     // 算力点
    admin: false,
    email: "",
    phonenumber: "",
    sex: "",
    avatar: "",
    password: "",
    status: "",
    delFlag: "",
    loginIp: "",
    loginDate: "",
    createTime: "",
    updateTime: "",
  },
  roles: [],
  permissions: []
}
